package com.gxy.learn.thread.example;

/**
 * @description:
 * @author: gaoxueyong
 * @Date: 2022/11/10 11:07
 */
public class ThreadSynchronizedTest {
    synchronized void m1() {
        for (int i = 0; i < 10; i++) {
            System.out.println(i);
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    synchronized void m2(){
        System.out.println("m2");
    }
    synchronized void m3() {
        for (int i = 10; i < 20; i++) {
            System.out.println(i);
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        ThreadSynchronizedTest tt = new ThreadSynchronizedTest();
        new Thread(tt::m1).start();
        new Thread(tt::m2).start();
        new Thread(tt::m3).start();
    }
}
